
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/12/2010 16:14:16
-- Generated from EDMX file: C:\Users\Goran\Documents\Visual Studio 10\Projects\New folder\BookID\BookID\BookID.Data\DataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [BookID];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_PostCommentAssoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Comments] DROP CONSTRAINT [FK_PostCommentAssoc];
GO
IF OBJECT_ID(N'[dbo].[FK_AlbumPhotoAssoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Photo] DROP CONSTRAINT [FK_AlbumPhotoAssoc];
GO
IF OBJECT_ID(N'[dbo].[FK_ThreadMessageAssoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Messages] DROP CONSTRAINT [FK_ThreadMessageAssoc];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseSubjectBaseObjectAssoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects] DROP CONSTRAINT [FK_BaseSubjectBaseObjectAssoc];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseSubjectPostAssoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Posts] DROP CONSTRAINT [FK_BaseSubjectPostAssoc];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseSubjectRelationhipAssoc1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Relationship] DROP CONSTRAINT [FK_BaseSubjectRelationhipAssoc1];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseSubjectRelationshipAssoc2]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Relationship] DROP CONSTRAINT [FK_BaseSubjectRelationshipAssoc2];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseObjectPostAssoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Posts] DROP CONSTRAINT [FK_BaseObjectPostAssoc];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseSubjectNotificationAssoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notifications] DROP CONSTRAINT [FK_BaseSubjectNotificationAssoc];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseSubjectThreadAssoc_BaseSubject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseSubjectThreadAssoc] DROP CONSTRAINT [FK_BaseSubjectThreadAssoc_BaseSubject];
GO
IF OBJECT_ID(N'[dbo].[FK_BaseSubjectThreadAssoc_Thread]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseSubjectThreadAssoc] DROP CONSTRAINT [FK_BaseSubjectThreadAssoc_Thread];
GO
IF OBJECT_ID(N'[dbo].[FK_Album_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Album] DROP CONSTRAINT [FK_Album_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Photo_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Photo] DROP CONSTRAINT [FK_Photo_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Relationship_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Relationship] DROP CONSTRAINT [FK_Relationship_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Status_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Status] DROP CONSTRAINT [FK_Status_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Link_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Link] DROP CONSTRAINT [FK_Link_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Video_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Video] DROP CONSTRAINT [FK_Video_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_Note_inherits_BaseObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseObjects_Note] DROP CONSTRAINT [FK_Note_inherits_BaseObject];
GO
IF OBJECT_ID(N'[dbo].[FK_User_inherits_BaseSubject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseSubjects_User] DROP CONSTRAINT [FK_User_inherits_BaseSubject];
GO
IF OBJECT_ID(N'[dbo].[FK_Group_inherits_BaseSubject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseSubjects_Group] DROP CONSTRAINT [FK_Group_inherits_BaseSubject];
GO
IF OBJECT_ID(N'[dbo].[FK_Event_inherits_BaseSubject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseSubjects_Event] DROP CONSTRAINT [FK_Event_inherits_BaseSubject];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Posts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Posts];
GO
IF OBJECT_ID(N'[dbo].[Comments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Comments];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects];
GO
IF OBJECT_ID(N'[dbo].[Threads]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Threads];
GO
IF OBJECT_ID(N'[dbo].[Messages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Messages];
GO
IF OBJECT_ID(N'[dbo].[BaseSubjects]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseSubjects];
GO
IF OBJECT_ID(N'[dbo].[Notifications]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Notifications];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Album]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Album];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Photo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Photo];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Relationship]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Relationship];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Status]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Status];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Link]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Link];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Video]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Video];
GO
IF OBJECT_ID(N'[dbo].[BaseObjects_Note]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseObjects_Note];
GO
IF OBJECT_ID(N'[dbo].[BaseSubjects_User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseSubjects_User];
GO
IF OBJECT_ID(N'[dbo].[BaseSubjects_Group]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseSubjects_Group];
GO
IF OBJECT_ID(N'[dbo].[BaseSubjects_Event]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseSubjects_Event];
GO
IF OBJECT_ID(N'[dbo].[BaseSubjectThreadAssoc]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseSubjectThreadAssoc];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Posts'
CREATE TABLE [dbo].[Posts] (
    [Id] uniqueidentifier  NOT NULL,
    [Title] nvarchar(255)  NULL,
    [Description] nvarchar(1024)  NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Created] datetime  NOT NULL,
    [BaseSubjectId] uniqueidentifier  NOT NULL,
    [BaseObjectId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'Comments'
CREATE TABLE [dbo].[Comments] (
    [Id] uniqueidentifier  NOT NULL,
    [Content] nvarchar(1024)  NOT NULL,
    [Created] datetime  NOT NULL,
    [PostId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects'
CREATE TABLE [dbo].[BaseObjects] (
    [Id] uniqueidentifier  NOT NULL,
    [Name] nvarchar(255)  NULL,
    [Description] nvarchar(1024)  NULL,
    [Created] datetime  NOT NULL,
    [BaseSubjectId] uniqueidentifier  NOT NULL,
    [Type] smallint  NOT NULL
);
GO

-- Creating table 'Threads'
CREATE TABLE [dbo].[Threads] (
    [Id] uniqueidentifier  NOT NULL,
    [Subject] nvarchar(255)  NOT NULL,
    [Created] datetime  NOT NULL
);
GO

-- Creating table 'Messages'
CREATE TABLE [dbo].[Messages] (
    [Id] uniqueidentifier  NOT NULL,
    [Body] nvarchar(max)  NOT NULL,
    [Created] datetime  NOT NULL,
    [ThreadId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseSubjects'
CREATE TABLE [dbo].[BaseSubjects] (
    [Id] uniqueidentifier  NOT NULL,
    [Username] nvarchar(255)  NULL,
    [Type] smallint  NOT NULL
);
GO

-- Creating table 'Notifications'
CREATE TABLE [dbo].[Notifications] (
    [Id] uniqueidentifier  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Created] datetime  NOT NULL,
    [Active] bit  NOT NULL,
    [BaseSubjectId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Album'
CREATE TABLE [dbo].[BaseObjects_Album] (
    [Location] nvarchar(255)  NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Photo'
CREATE TABLE [dbo].[BaseObjects_Photo] (
    [AlbumId] uniqueidentifier  NOT NULL,
    [FileType] nvarchar(10)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Relationship'
CREATE TABLE [dbo].[BaseObjects_Relationship] (
    [Status] smallint  NOT NULL,
    [BaseSubjectId1] uniqueidentifier  NOT NULL,
    [BaseSubjectId2] uniqueidentifier  NOT NULL,
    [RelationType] smallint  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Status'
CREATE TABLE [dbo].[BaseObjects_Status] (
    [Content] nvarchar(1024)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Link'
CREATE TABLE [dbo].[BaseObjects_Link] (
    [Url] nvarchar(max)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Video'
CREATE TABLE [dbo].[BaseObjects_Video] (
    [EmbedCode] nvarchar(max)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseObjects_Note'
CREATE TABLE [dbo].[BaseObjects_Note] (
    [Title] nvarchar(1024)  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseSubjects_User'
CREATE TABLE [dbo].[BaseSubjects_User] (
    [Email] nvarchar(512)  NOT NULL,
    [Password] nvarchar(20)  NOT NULL,
    [FirstName] nvarchar(50)  NOT NULL,
    [LastName] nvarchar(100)  NOT NULL,
    [Birthday] datetime  NULL,
    [WebSite] nvarchar(1024)  NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseSubjects_Group'
CREATE TABLE [dbo].[BaseSubjects_Group] (
    [Name] nvarchar(512)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseSubjects_Event'
CREATE TABLE [dbo].[BaseSubjects_Event] (
    [StartDate] nvarchar(max)  NOT NULL,
    [EndDate] nvarchar(max)  NOT NULL,
    [Location] nvarchar(255)  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'BaseSubjectThreadAssoc'
CREATE TABLE [dbo].[BaseSubjectThreadAssoc] (
    [BaseSubjects_Id] uniqueidentifier  NOT NULL,
    [Threads_Id] uniqueidentifier  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [PK_Posts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Comments'
ALTER TABLE [dbo].[Comments]
ADD CONSTRAINT [PK_Comments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects'
ALTER TABLE [dbo].[BaseObjects]
ADD CONSTRAINT [PK_BaseObjects]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Threads'
ALTER TABLE [dbo].[Threads]
ADD CONSTRAINT [PK_Threads]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [PK_Messages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseSubjects'
ALTER TABLE [dbo].[BaseSubjects]
ADD CONSTRAINT [PK_BaseSubjects]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Notifications'
ALTER TABLE [dbo].[Notifications]
ADD CONSTRAINT [PK_Notifications]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Album'
ALTER TABLE [dbo].[BaseObjects_Album]
ADD CONSTRAINT [PK_BaseObjects_Album]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Photo'
ALTER TABLE [dbo].[BaseObjects_Photo]
ADD CONSTRAINT [PK_BaseObjects_Photo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Relationship'
ALTER TABLE [dbo].[BaseObjects_Relationship]
ADD CONSTRAINT [PK_BaseObjects_Relationship]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Status'
ALTER TABLE [dbo].[BaseObjects_Status]
ADD CONSTRAINT [PK_BaseObjects_Status]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Link'
ALTER TABLE [dbo].[BaseObjects_Link]
ADD CONSTRAINT [PK_BaseObjects_Link]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Video'
ALTER TABLE [dbo].[BaseObjects_Video]
ADD CONSTRAINT [PK_BaseObjects_Video]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseObjects_Note'
ALTER TABLE [dbo].[BaseObjects_Note]
ADD CONSTRAINT [PK_BaseObjects_Note]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseSubjects_User'
ALTER TABLE [dbo].[BaseSubjects_User]
ADD CONSTRAINT [PK_BaseSubjects_User]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseSubjects_Group'
ALTER TABLE [dbo].[BaseSubjects_Group]
ADD CONSTRAINT [PK_BaseSubjects_Group]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseSubjects_Event'
ALTER TABLE [dbo].[BaseSubjects_Event]
ADD CONSTRAINT [PK_BaseSubjects_Event]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [BaseSubjects_Id], [Threads_Id] in table 'BaseSubjectThreadAssoc'
ALTER TABLE [dbo].[BaseSubjectThreadAssoc]
ADD CONSTRAINT [PK_BaseSubjectThreadAssoc]
    PRIMARY KEY NONCLUSTERED ([BaseSubjects_Id], [Threads_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [PostId] in table 'Comments'
ALTER TABLE [dbo].[Comments]
ADD CONSTRAINT [FK_PostCommentAssoc]
    FOREIGN KEY ([PostId])
    REFERENCES [dbo].[Posts]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostCommentAssoc'
CREATE INDEX [IX_FK_PostCommentAssoc]
ON [dbo].[Comments]
    ([PostId]);
GO

-- Creating foreign key on [AlbumId] in table 'BaseObjects_Photo'
ALTER TABLE [dbo].[BaseObjects_Photo]
ADD CONSTRAINT [FK_AlbumPhotoAssoc]
    FOREIGN KEY ([AlbumId])
    REFERENCES [dbo].[BaseObjects_Album]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AlbumPhotoAssoc'
CREATE INDEX [IX_FK_AlbumPhotoAssoc]
ON [dbo].[BaseObjects_Photo]
    ([AlbumId]);
GO

-- Creating foreign key on [ThreadId] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [FK_ThreadMessageAssoc]
    FOREIGN KEY ([ThreadId])
    REFERENCES [dbo].[Threads]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ThreadMessageAssoc'
CREATE INDEX [IX_FK_ThreadMessageAssoc]
ON [dbo].[Messages]
    ([ThreadId]);
GO

-- Creating foreign key on [BaseSubjectId] in table 'BaseObjects'
ALTER TABLE [dbo].[BaseObjects]
ADD CONSTRAINT [FK_BaseSubjectBaseObjectAssoc]
    FOREIGN KEY ([BaseSubjectId])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseSubjectBaseObjectAssoc'
CREATE INDEX [IX_FK_BaseSubjectBaseObjectAssoc]
ON [dbo].[BaseObjects]
    ([BaseSubjectId]);
GO

-- Creating foreign key on [BaseSubjectId] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [FK_BaseSubjectPostAssoc]
    FOREIGN KEY ([BaseSubjectId])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseSubjectPostAssoc'
CREATE INDEX [IX_FK_BaseSubjectPostAssoc]
ON [dbo].[Posts]
    ([BaseSubjectId]);
GO

-- Creating foreign key on [BaseSubjectId1] in table 'BaseObjects_Relationship'
ALTER TABLE [dbo].[BaseObjects_Relationship]
ADD CONSTRAINT [FK_BaseSubjectRelationhipAssoc1]
    FOREIGN KEY ([BaseSubjectId1])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseSubjectRelationhipAssoc1'
CREATE INDEX [IX_FK_BaseSubjectRelationhipAssoc1]
ON [dbo].[BaseObjects_Relationship]
    ([BaseSubjectId1]);
GO

-- Creating foreign key on [BaseSubjectId2] in table 'BaseObjects_Relationship'
ALTER TABLE [dbo].[BaseObjects_Relationship]
ADD CONSTRAINT [FK_BaseSubjectRelationshipAssoc2]
    FOREIGN KEY ([BaseSubjectId2])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseSubjectRelationshipAssoc2'
CREATE INDEX [IX_FK_BaseSubjectRelationshipAssoc2]
ON [dbo].[BaseObjects_Relationship]
    ([BaseSubjectId2]);
GO

-- Creating foreign key on [BaseObjectId] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [FK_BaseObjectPostAssoc]
    FOREIGN KEY ([BaseObjectId])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseObjectPostAssoc'
CREATE INDEX [IX_FK_BaseObjectPostAssoc]
ON [dbo].[Posts]
    ([BaseObjectId]);
GO

-- Creating foreign key on [BaseSubjectId] in table 'Notifications'
ALTER TABLE [dbo].[Notifications]
ADD CONSTRAINT [FK_BaseSubjectNotificationAssoc]
    FOREIGN KEY ([BaseSubjectId])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseSubjectNotificationAssoc'
CREATE INDEX [IX_FK_BaseSubjectNotificationAssoc]
ON [dbo].[Notifications]
    ([BaseSubjectId]);
GO

-- Creating foreign key on [BaseSubjects_Id] in table 'BaseSubjectThreadAssoc'
ALTER TABLE [dbo].[BaseSubjectThreadAssoc]
ADD CONSTRAINT [FK_BaseSubjectThreadAssoc_BaseSubject]
    FOREIGN KEY ([BaseSubjects_Id])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Threads_Id] in table 'BaseSubjectThreadAssoc'
ALTER TABLE [dbo].[BaseSubjectThreadAssoc]
ADD CONSTRAINT [FK_BaseSubjectThreadAssoc_Thread]
    FOREIGN KEY ([Threads_Id])
    REFERENCES [dbo].[Threads]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BaseSubjectThreadAssoc_Thread'
CREATE INDEX [IX_FK_BaseSubjectThreadAssoc_Thread]
ON [dbo].[BaseSubjectThreadAssoc]
    ([Threads_Id]);
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Album'
ALTER TABLE [dbo].[BaseObjects_Album]
ADD CONSTRAINT [FK_Album_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Photo'
ALTER TABLE [dbo].[BaseObjects_Photo]
ADD CONSTRAINT [FK_Photo_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Relationship'
ALTER TABLE [dbo].[BaseObjects_Relationship]
ADD CONSTRAINT [FK_Relationship_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Status'
ALTER TABLE [dbo].[BaseObjects_Status]
ADD CONSTRAINT [FK_Status_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Link'
ALTER TABLE [dbo].[BaseObjects_Link]
ADD CONSTRAINT [FK_Link_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Video'
ALTER TABLE [dbo].[BaseObjects_Video]
ADD CONSTRAINT [FK_Video_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseObjects_Note'
ALTER TABLE [dbo].[BaseObjects_Note]
ADD CONSTRAINT [FK_Note_inherits_BaseObject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseObjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseSubjects_User'
ALTER TABLE [dbo].[BaseSubjects_User]
ADD CONSTRAINT [FK_User_inherits_BaseSubject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseSubjects_Group'
ALTER TABLE [dbo].[BaseSubjects_Group]
ADD CONSTRAINT [FK_Group_inherits_BaseSubject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseSubjects_Event'
ALTER TABLE [dbo].[BaseSubjects_Event]
ADD CONSTRAINT [FK_Event_inherits_BaseSubject]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseSubjects]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------